# Figure B.6: Survey and Administrative Turnout


# 1. Load Packages ----

library(tidyverse)

# 2. Read in Data ----

load(file = "df_voxit_props.RData")

load(file = "df_voxit_individual_analysis.RData")

# 3. Data Preparation ----
# Generate average turnout in admin and survey data

df_ind <- voxit_individual %>% 
  group_by(datum_merge) %>%
  summarize(turnout_mean=mean(turnout,na.rm=T)) %>%
  mutate(source=1)

df_vox <- voxit_props %>% 
  group_by(datum_merge) %>%
  summarize(turnout_mean=mean(turnout,na.rm=T)) %>%
  mutate(source=2)



# 4. Plot ----

# Change Language
#Sys.setlocale("LC_ALL", "English")

df_ind %>% 
  bind_rows(df_vox) %>%
  ggplot(aes(x=datum_merge,y=turnout_mean,
             linetype=factor(source),
             shape=factor(source))) + 
  geom_point() + 
  geom_line()+
  xlab("") + ylab("Turnout") + 
  theme_bw() + 
  scale_x_date(breaks= seq(min(df_vox$datum_merge), 
                           max(df_vox$datum_merge), 
                           length=10), 
               date_labels="%b %Y") +
  scale_linetype_manual(name= "", 
                        values=c(1,2),
                        labels = c("Survey turnout",
                                   "Administrative turnout")) +
  scale_shape_manual(name= "", 
                     values=c(16,2),
                     labels = c("Survey turnout",
                                "Administrative turnout")) +
  theme(legend.position="bottom")


# 5. Save Plot ----
ggsave(filename = "FigureB6.pdf", width = 7.58, height = 5.3)

